# -*- coding:utf-8 -*-
from flask import render_template, request, jsonify
from flask_mail import Message
from .. import app
from .. import mail
from .. import celery, cache
from ..models import *
import json

from ..utils import send_email


#发送邮件
@celery.task(name="task.send")
def task_allocation():
    '''
    分配任务：使用celery控制flask-mail发送邮件
    '''
    with app.app_context():
        email_users = Orders.objects().all()
        for email_user in email_users:
            receivers = email_user.email
            template = 'example.html'
            content = Newest.objects(url=email_user.url).first()
            print(type(content))
            send_email.delay(receivers, template, content=content.content)
